package com.coldchain.admin.config.api;

import com.coldchain.admin.config.entity.CarTypeSearch;
import com.coldchain.admin.config.service.ICarTypeService;
import com.coldchain.authclient.annotation.CheckUserToken;
import com.coldchain.common.exception.base.BusinessException;
import com.coldchain.common.msg.ObjectRestResponse;
import com.coldchain.common.vo.CarTypeVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 车型 前端控制器
 * </p>
 *
 * @author fangliai
 * @since 2018-09-13
 */
@RestController
@RequestMapping("/cartype")
@CheckUserToken
public class CarTypeController {
    private static Logger log= LoggerFactory.getLogger(CarTypeController.class);
    @Autowired
    private ICarTypeService carTypeService;



    /**
     * 获取所有车辆类型
     * @return
     */
    @RequestMapping("/all")
    public ObjectRestResponse<List<CarTypeVo>> getAll(){
        return  new ObjectRestResponse<>().data(carTypeService.getAllCarType());
    }

    /**
     * 高及查询
     * @param {查询对象}  search
     * @return
     */
    @PostMapping("/search")
    public ObjectRestResponse<List<CarTypeVo>> list(CarTypeSearch search){
         return  new ObjectRestResponse<>().data(carTypeService.search(search));
    }

    @PostMapping("/add")
    public Object add(String params)throws BusinessException{
        carTypeService.addCarType(params);
        return new ObjectRestResponse<>().succeed("ok");
    }

    @PostMapping("/del/{id}")
    public  Object del(@PathVariable("id") Long id){
         carTypeService.removeById(id);
         return  new ObjectRestResponse<>().succeed();
    }





    @GetMapping("/{id}")
    public  ObjectRestResponse<CarTypeVo> getCarTypeInfo(@PathVariable("id") Integer id){
        return  new ObjectRestResponse<>().data(carTypeService.getCarTypeVoInfoById(id));
    }


}
